package thread;

//创建线程 方法1:继承Thread 重写run方法
class MyThreadDemo extends Thread{
    @Override
    public void run() {
        while(true){
            System.out.println("run方法在执行");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}

public class ThreadDemo1 {
    public static void main(String[] args) {
        Thread thread = new MyThreadDemo();
        thread.start();
        while(true){
            System.out.println("main方法在执行");
            try {
                Thread.sleep(1000);//让代码停1000毫秒(1秒)
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
